<%@page contentType="text/html;charset=utf-8"%>
<%@include file="../../core/common.jsp"%>
<html>
<head>
<title></title>
</head>
<body>
	<div id="tb" class="toolbar">
		<div style="float: left;">
			<a id="add" class="form-btn primary">
				<i class="fa fa-plus-square"></i>
			</a>
			<a id="remove" class="form-btn danger">
				<i class="fa fa-minus-square"></i>
			</a>
			<a id="save" class="form-btn success">
				<i class="fa fa-save m-r-5"></i>保存
			</a>
		</div>
		<div style="float: right;">
			<a id="find" class="form-btn success">
				<i class="fa fa-refresh m-r-5"></i>刷新
			</a>
		</div>
		<div style="clear: both;"></div>
	</div>
	<table id="eg" class="easyui-edatagrid" data-options="url:'${CTX}/mgt/t/ys/find',toolbar:'#tb'">
		<thead>
			<tr>
				<th data-options="field:'ys',width:150" editor="{type:'textbox',options:{required:true,validType:'maxLength[50]'}}">元素</th>
				<th data-options="field:'sx',width:150" editor="{type:'textbox'}">上限</th>
				<th data-options="field:'xx',width:150" editor="{type:'textbox'}">下限</th>
				<th data-options="field:'pc',width:150" editor="{type:'textbox'}">偏差</th>
				<th data-options="field:'cx',width:150" editor="{type:'numberspinner',options:{required:true,min:1,max:100}}">顺序</th>
			</tr>
		</thead>
	</table>
</body>
<script>
	$(function() {
		$('#find').click(function() {
			$('#eg').edatagrid('reload');
		});
		$('#add').click(function() {
			$('#eg').edatagrid('addRow');
		});
		$('#remove').click(function() {
			var row = $('#eg').edatagrid('getSelected');
			if (row) {
				$('#eg').edatagrid('destroyRow');
			} else {
				$.info('请选择元素');
			}
		});
		$('#save').click(function() {
			var data = $('#eg').edatagrid('getRows');
			for(var i in data){
				var rowIndex = $('#eg').edatagrid('getRowIndex', data[i]);
				$('#eg').edatagrid('beginEdit', rowIndex);
				if (!$('#eg').edatagrid('validateRow', rowIndex)) {
					return;
				}
				$('#eg').edatagrid('endEdit', rowIndex);
			}
			$.mask();
			$.ajax({
				url : '${CTX}/mgt/t/ys/save',
				data : {
					json : JSON.stringify(data)
				},
				success : function(data) {
					$.unmask();
					$.handle(data, function() {
						$('#find').click();
					});
				}
			});
		});
	});
</script>
</html>